Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified how entrust adds permissions #929

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Modified how entrust adds permissions #929

wants to merge 1 commit into from

Conversation

blakethepatton
Copy link

This way, duplicate records aren't added and foreign key constraints don't become an issue.

@mazeeblanke
Copy link

This way, duplicate records aren't added and foreign key constraints don't become an issue.

The sync method takes in an array, and any item with its id missing from that array will be removed https://laravel.com/docs/5.7/eloquent-relationships#Syncing-Associations. Based on the docs you cannot do this
$this->perms()->sync($permission, false);

@blakethepatton
Copy link
Author

Based on the docs you cannot do this

Based on the actual complete documentation, the laravel api docs, you can do this without removing records. The sync method acutally takes in a collection OR an array, as well as an optional boolean. Perhaps you didn't notice that I set the second parameter to false?

The documentation:
https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.html#method_sync

The actual source file:
https://github.com/laravel/framework/blob/5.7/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants